﻿using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class UserInfoItem:MonoBehaviour
{
    public NetworkImage iconImg;
    public Text nameText;
    public Text statusText;
    public Text birthYear;
    public Text location;
    public Text hometown;
    public Text height;
    public Text eduation;
    public Text job;
    public RawImage momentTex1;
    public RawImage momentTex2;
    public RawImage momentTex3;

    public HorizontalLayoutGroup line2Layout;
    public HorizontalLayoutGroup line3Layout;

    UserInfo m_UserInfo;
    public UserInfo userInfo => m_UserInfo;


    void Start()
    {
        momentTex1.gameObject.SetActive(false);
        momentTex2.gameObject.SetActive(false);
        momentTex3.gameObject.SetActive(false);
    }
    public void Init(UserInfo userInfo)
    {
        m_UserInfo = userInfo;

        var iconRect = iconImg.GetComponent<RectTransform>();
        iconImg.Init(userInfo.icon);
        nameText.text = userInfo.name;
        birthYear.text = userInfo.birthYear % 1900 + "年";
        location.text = "现居"+ userInfo.locationProvince+userInfo.locationCity;
        hometown.text = userInfo.hometownCity;
        height.text = userInfo.height + "cm";
        eduation.text = DataString.GetEducationString(userInfo.eduation);
        job.text = userInfo.job;
        if(statusText)
            statusText.text = userInfo.status;

        StartCoroutine(UpdateLayout());
    }

    IEnumerator UpdateLayout()
    {
        int count = 0;
        for(int i = 0; i < 30; i++)
        {
            count++;

            line2Layout.enabled = !line2Layout.enabled;
            line3Layout.enabled = !line3Layout.enabled;
            yield return null;
        }
        line2Layout.enabled = true;
        line3Layout.enabled = true;
    }
}
